const { app, BrowserWindow, desktopCapturer, session } = require('electron')


let mainWin = null
const createWindow = () => {
  mainWin = new BrowserWindow({
    width: 1000,
    height: 800,
    title: '自定义菜单',
    webPreferences: {
      // 允许渲染进程使用nodejs
      nodeIntegration: true,
      // 允许渲染进程使用nodejs
      contextIsolation: false,
    }
  })

  session.defaultSession.setDisplayMediaRequestHandler((request, callback) => {
    desktopCapturer.getSources({ types: ['screen'] }).then((sources) => {
      // Grant access to the first screen found.
      console.log(sources)
      callback({ video: sources[0], audio: "loopback" })
    })
  })

  mainWin.loadURL('https://hkmeeting.schkzy.com/')
  mainWin.webContents.openDevTools()
}

app.whenReady().then(() => {
  createWindow()
  app.on('activate', () => {
    if (BrowserWindow.getAllWindows().length === 0) {
      createWindow()
    }
  })
})

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})


